﻿package game.objects {
	import flash.display.BitmapData;
	import flash.display.Bitmap;
	import flash.geom.Matrix;
	
	public class DynamicObject {
		
		public static const POSITION_BOTTOM:String	= "-stage.height";
		public static const POSITION_RIGHT:String	= "-stage.width";
		public static const POSITION_CENTER:String	= "stage.width/2";
		
		public static const FRIENDS:String		= "type.friends";
		public static const ERROR:String		= "type.error";
		public static const HEADER:String		= "type.header";
		public static const SUB_MENU:String		= "type.sub";
		public static const SHOP_CAR:String		= "type.shop.car";
		public static const SHOP_DONAT:String	= "type.shop.donat";
		
		public var type:String;
		public var center:BitmapData;
		public var top:BitmapData;
		public var bottom:BitmapData;
		public var left:BitmapData;
		public var right:BitmapData;
		public var width:String;
		public var height:String;
		public var x:String;
		public var y:String;
		public var hide:Boolean;
		public var conainerTop:String;
		public var conainerBottom:String;
		public var conainerLeft:String;
		public var conainerRight:String;
		public var elements:Vector.<DynamicElement>;
		
		public function DynamicObject(type:String, center:BitmapData, top:BitmapData = null, bottom:BitmapData = null, left:BitmapData = null, right:BitmapData = null, width:String = null, height:String = null, x:String = null, y:String = null, conainerTop:String = null, conainerBottom:String = null, conainerLeft:String = null, conainerRight:String = null, hide:Boolean = false, elements:Vector.<DynamicElement> = null):void {
			
			this.type		= type;
			this.center		= center;
			this.top		= top;
			this.bottom		= bottom;
			this.left		= left;
			this.right		= right;
			this.width		= width;
			this.height		= height;
			this.x			= x;
			this.y			= y;
			this.hide		= hide;
			this.conainerTop	= (conainerTop)		? conainerTop		: '0px';
			this.conainerBottom	= (conainerBottom)	? conainerBottom	: '0px';
			this.conainerLeft	= (conainerLeft)	? conainerLeft		: '0px';
			this.conainerRight	= (conainerRight)	? conainerRight 	: '0px';
			this.elements	= elements;
			
		}
		
		public static function reverse(bitmapData:BitmapData, type:String):BitmapData {
			var bitmap:Bitmap = new Bitmap (bitmapData);
			var b:BitmapData = new BitmapData (bitmapData.width, bitmapData.height, true, 0x000000);
			var matrix:Matrix = bitmap.transform.matrix;
			switch (type) {
				case 'x':
					matrix.a = -1;
					matrix.tx = bitmap.width;
				break;
				case 'y':
					matrix.d = -1;
					matrix.ty = bitmap.height;
				break;
			}
			
			b.draw(bitmap, matrix);
			return b;
		}
		
	}
	
}